//
//  NSString+LCBase64.m
//  UI_24_加密
//
//  Created by li cheng on 16/8/16.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "NSString+LCBase64.h"

@implementation NSString (LCBase64)
// 编码
- (NSString *)stringWithBase64{
    // 字符串 转 NSData
    NSData *stringData = [self dataUsingEncoding:NSUTF8StringEncoding];
    // NSData 进行 Base64, 生成字符串
    NSString *base64String = [stringData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    return base64String;
}
- (NSData *)base64StringWithData{
    return [[NSData alloc] initWithBase64EncodedString:self options:NSDataBase64DecodingIgnoreUnknownCharacters];
}
// 解码
- (NSString *)base64WithString{
    // 根据 base64 字符串, 生成NSData
    NSData *base64Data = [self base64StringWithData];
    // 把 NSData 转成字符串
    NSString *orginString = [[NSString alloc] initWithData:base64Data encoding:NSUTF8StringEncoding];
    return orginString;
}
@end
